<!doctype html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<link rel="stylesheet" href="../css/mui.min.css">
		<link rel="stylesheet" type="text/css" href="../css/mui.picker.min.css" />
		<link rel="stylesheet" href="../css/iconfont.css">
		<style>
			.mui-content-padded{margin:5px 0 0 0;}
			.mui-row-list span{float: left; line-height:33px; width:20%;}
			.mui-row-list select{float: left; line-height:14px; font-size:14px; margin-top:2px; margin-left: 5px;}
			.mui-btn-block{margin-bottom:0; padding:6px;}
			.mui-col-sm-12{ border-top: 1px solid #D1D1D1; width:100%; padding-top:5px; font-size:14px;}
			input[type="number"]{height:26px; padding: 0;border-width:0;margin-bottom:0;background:none;}
			form:before{ background: none !important; border: none !important;}
			input{border-width:0; float: right; text-align: right; padding-right: 15px; font-size:14px; height: 26px;}
			.mui-switch{
				border-color: #007AFF;
				background-color: #007AFF;
				border-width: 1px;
			}
			.mui-switch:before {content: '无症状'; color: #fff; right: 5px;}
			.mui-switch.mui-active:before {content: '有'; color: #fff; left: 15px;}
			.mui-switch.mui-active {
				border-color: #fd933b;
				background-color: #fd933b;
			}
			.mui-ul-check{ width: 100%; margin: 0; padding: 0;}
			.mui-ul-check li{float: left; list-style-type:none; text-align: center; padding:5px; margin:2px; border:1px solid #D1D1D1;}
			.mui-ul-check li.on{ background-color:#007AFF; color:#FFFFFF; float: left; list-style-type:none; text-align: center; padding:5px; margin:2px;}	
			.bottom_soild{border-bottom: 1px solid #DDDDDD; margin-right: 5px;}
			.submit{
				margin:0 auto 10px auto; 
				width:200px; 
				height:35px; 
				line-height: 35px; 
				background-color:#007AFF; 
				text-align: center; 
				color: #FFFFFF; 
				border-radius: 10px;
				margin-top: 10px;
			}
		</style>
	</head>

	<body>
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title">体征录入</h1>
		</header>
		<div class="mui-conten" style="margin-top:50px;">
			<ul class="mui-table-view" style="margin-top: 5px;">
				<div class="mui-row">
					<div class="mui-col-sm-12 mui-col-xs-12">
						<li class="mui-table-view-cell">
							<a id='demo2' data-options='{"type":"date"}' class="btn mui-navigate-right">
								<div style="float: left; font-size: 16px; line-height: 26px;">痰菌情况</div>
								<input id='result0' class="ui-alert" placeholder="请选择" style="width:50%; float:right; margin-right:15px;"/>
							</a>
						</li>
						<li class="mui-table-view-cell">
							<a id='demo2' data-options='{"type":"date"}' class="btn mui-navigate-right">
								<div style="float: left; font-size: 16px; line-height: 26px;">患者类型</div>
								<input id='result1' class="ui-alert" placeholder="请选择" style="width:50%; float:right; margin-right:15px;"/>
							</a>
						</li>
						<li class="mui-table-view-cell">
							<a id='demo2' data-options='{"type":"date"}' class="btn mui-navigate-right">
								<div style="float: left; font-size: 16px; line-height: 26px;">耐药情况</div>
								<input id='result2' class="ui-alert" placeholder="请选择" style="width:50%; float:right; margin-right:15px;"/>
							</a>
						</li>
						<li class="mui-table-view-cell">
							<div style="float: left; width: 100%; line-height: 26px;">
								<div style="float: left; font-size: 16px; line-height: 26px;">治疗月序</div>
								<div style="float: right; font-size: 16px; margin: 0 5px; padding: 0; line-height: 26px;">月</div>
								<input id='month' type="number" class="ui-alert border0" placeholder="" style="width:50px; float: right; text-align: center;"/>
								<div style="float: right; font-size: 16px; margin: 0 5px; padding: 0; line-height: 26px;">第</div>
							</div>
						</li>
					</div>
				</div>
			</ul>
			<div onclick="submit()" class="submit" >保存</div>
		</div>
		<script src="../js/mui.js"></script>
		<script src="../js/mui.picker.min.js"></script>
		<script src="../js/jquery.min-1.11.1.js"></script>
		<script src="../js/request.js"></script>
		<script type="text/javascript">
			//获取变量
			var self = localStorage.getItem("name")
			console.log(self)
			var dataold = JSON.parse(self)
			var obj = dataold.obj
			var selfdata ="";
			var listdata ="";
			mui.plusReady(function(){
				var self = plus.webview.currentWebview()
					listdata = self.data;
					visitId = self.visitdata;
					selfdata = JSON.parse(listdata)
				var date1 = new Date();
				var year1=date1.getFullYear(); 
				var month1=date1.getMonth()+1;
				var day1=date1.getDate();
				var h1=date1.getHours();
				var m1=date1.getMinutes();
				var s1=date1.getSeconds();
					month1 =(month1<10 ? "0"+month1:month1); 
					day1 =(day1<10 ? "0"+day1:day1); 
					h1 =(h1<10 ? "0"+h1:h1); 
					m1 =(m1<10 ? "0"+m1:m1); 
					s1 =(s1<10 ? "0"+s1:s1);
					createDate = (year1.toString()+'-'+month1.toString()+'-'+day1.toString()+' '+h1.toString()+':'+m1.toString()+':'+s1.toString());
					modifyDate = (year1.toString()+'-'+month1.toString()+'-'+day1.toString()+' '+h1.toString()+':'+m1.toString()+':'+s1.toString());
					ehrId = selfdata.ehrId;
					tbId = self.arcid;
				if(self.second != ""){
					first = JSON.parse(self.first);
					second = JSON.parse(self.second);
					id = first.id;
					createUser = first.createUser;
					createDate = first.createDate;
					for(var i=0; i<second.length; i++){
						if(second[i].questionId == "901"){
							var rowsbacteria=resultall.r1;
							for(var j=0; j<rowsbacteria.length; j++){
								if(second[i].answerId == rowsbacteria[j].id){
									document.getElementById("result0").value = rowsbacteria[j].text;
								}
							}
						}
						if(second[i].questionId == "900"){
							var rowspatientstype=resultall.r2;
							for(var j=0; j<rowspatientstype.length; j++){
								if(second[i].answerId == rowspatientstype[j].id){
									document.getElementById("result1").value = rowspatientstype[j].text;
								}
							}
						}
						if(second[i].questionId == "902"){
							var rowsdrug=resultall.r3;
							for(var j=0; j<rowsdrug.length; j++){
								if(second[i].answerId == rowsdrug[j].id){
									document.getElementById("result2").value = rowsdrug[j].text;
								}
							}
						}
						if(second[i].questionId == "905"){
							document.getElementById("month").value = second[i].answer;
						}
					}
				}
			})
			//赋值
			var resultall = {"r1":[{id:'0',text:' '},{id:'1',text:'阳性'},{id:'2',text:'阴性'},{id:'3',text:'未查痰'}],
							"r2":[{id:'0',text:' '},{id:'1',text:'初治'},{id:'2',text:'复治'}],
							"r3":[{id:'0',text:' '},{id:'1',text:'耐药'},{id:'2',text:'非耐药'},{id:'3',text:'未检测'}]}
			var id = 0;
			var visitId= 0;
			var ehrId = "";
			var tbId ="";//肺结核专档id
			var createDate = "";
			var createUserid = obj.id;
			var modifyDate = "";
			var modifyUserid = obj.id;
			var patientstype = ""
			var drug = ""
			var bacteria = ""
			mui.init()
			(function($) {
				$.init();
				var result = $('#result')[0];
				var btns = $('.btn');
				btns.each(function(i, btn) {
					btn.addEventListener('tap', function() {
						var _self = this;
						if(_self.picker) {
							_self.picker.show(function (rs) {
								result.innerText = rs.text;
								_self.picker.dispose();
								_self.picker = null;
							});
						} else {
							if(i == 0){  
								var picker = new mui.PopPicker();
								 picker.setData([{id:'1',text:'阳性'},{id:'2',text:'阴性'},{id:'3',text:'未查痰'}]);
								 picker.show(function (selectItems) {
									 $('#result'+i)[0].value = selectItems[0].text;
									 bacteria = selectItems[0].id;
								  })
							}else if(i == 1){ 
								var picker = new mui.PopPicker();
								 picker.setData([{id:'1',text:'初治'},{id:'2',text:'复治'}]);
								 picker.show(function (selectItems) {
									 $('#result'+i)[0].value = selectItems[0].text;
									 patientstype = selectItems[0].id;
								  })
							}else if(i == 2){ 
								var picker = new mui.PopPicker();
								 picker.setData([{id:'1',text:'耐药'},{id:'2',text:'非耐药'},{id:'3',text:'未检测'}]);
								 picker.show(function (selectItems) {
									 $('#result'+i)[0].value = selectItems[0].text;
									 drug = selectItems[0].id;
								  })
							}else{
								
							}
						}
					}, false);
				});
			})(mui);
			//提交
			function submit(){
				bacteria_1 = $('#result0')[0].value;
				for(var re=0; re<resultall.r1.length; re++){
					if(bacteria_1 == resultall.r1[re].text){
						bacteria = resultall.r1[re].id;
					}
				}	
				patt_1 = $('#result1')[0].value;
				for(var re=0; re<resultall.r2.length; re++){
					if(patt_1 == resultall.r2[re].text){
						patientstype = resultall.r2[re].id;
					}
				}	
				drug_1 = $('#result2')[0].value;
				for(var re=0; re<resultall.r3.length; re++){
					if(drug_1 == resultall.r3[re].text){
						drug = resultall.r3[re].id;
					}
				}	
				var dataobj=[
						//治疗月序
						{'id':id,
						'ehrId':ehrId,
						'tbId':tbId,
						"visitId":visitId,
						"questionId":"905",
						"answerId":"0",
						"answer":mui("#month")[0].value,
						"expectedAnswerId":"0",
						"expectedAnswer":null,
						"createDate":createDate,
						"modifyDate":modifyDate,
						"createUserid":createUserid,
						"modifyUserid":modifyUserid},
						//痰菌情况
						{'id':id,
						'ehrId':ehrId,
						'tbId':tbId,
						"visitId":visitId,
						"questionId":"901",
						"answerId":bacteria,
						"answer":null,
						"expectedAnswerId":"0",
						"expectedAnswer":null,
						"createDate":createDate,
						"modifyDate":modifyDate,
						"createUserid":createUserid,
						"modifyUserid":modifyUserid},
						//患者类型
						{'id':id,
						'ehrId':ehrId,
						'tbId':tbId,
						"visitId":visitId,
						"questionId":"900",
						"answerId":patientstype,
						"answer":null,
						"expectedAnswerId":"0",
						"expectedAnswer":null,
						"createDate":createDate,
						"modifyDate":modifyDate,
						"createUserid":createUserid,
						"modifyUserid":modifyUserid},
						//耐药情况
						{'id':id,
						'ehrId':ehrId,
						'tbId':tbId,
						"visitId":visitId,
						"questionId":"902",
						"answerId":drug,
						"answer":null,
						"expectedAnswerId":"0",
						"expectedAnswer":null,
						"createDate":createDate,
						"modifyDate":modifyDate,
						"createUserid":createUserid,
						"modifyUserid":modifyUserid}
				]
				$.ajax({
					type: 'post',
					url:getRequestUrl.url+"/mobile/ehr/TbVisitAddition/addOrUpdate",
					data:JSON.stringify(dataobj),
					dataType:"json",
					contentType : 'application/json;charset=utf-8',
					success : function(data) {
						if(data.status==1){
							alert("提交成功")
							mui.openWindow({
								url: 'follow_up_add.html', 
								id:'follow_up_add',
								extras:{
								}
							});
						}else{
							alert(data.message);
						}
					},
					error:function(xhr,type,errorThrown){
						
					}
				})
			}
		</script>
	</body>

</html>